package com.znyj.cloud.device.pack;

import io.netty.channel.ChannelHandlerContext;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

import java.sql.Timestamp;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * Created by gaoliwei02 on 17/6/3.
 */
public class OnlineDeviceInfo {
    private String deviceId;
    private Timestamp updateTime;
    private ChannelHandlerContext ctx;
    private int timeout;
    private ReadWriteLock readWriteLock = new ReentrantReadWriteLock();

    public OnlineDeviceInfo(String deviceId, ChannelHandlerContext ctx, Timestamp updateTime,int timeout) {
        this.deviceId = deviceId;
        this.ctx = ctx;
        this.updateTime = updateTime;
        this.timeout = timeout;
    }

    @Override
    public String toString() {
        return ReflectionToStringBuilder.reflectionToString(this);
    }

    public Timestamp getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Timestamp updateTime) {
        this.updateTime = updateTime;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public ChannelHandlerContext getCtx() {
        return ctx;
    }

    public void setCtx(ChannelHandlerContext ctx) {
        this.ctx = ctx;
    }

    public int getTimeout() {
        return timeout;
    }

    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }
}

//    public boolean getIsDoing() {
//        boolean isDoing;
//        readWriteLock.readLock().lock();
//        try {
//            isDoing = this.isDoing;
//        } finally {
//            readWriteLock.readLock().unlock();
//        }
//        return isDoing;
//    }
//
//    public void setIsDoing(boolean isDoing) {
//        readWriteLock.writeLock().lock();
//        try {
//            this.isDoing = isDoing;
//        } finally {
//            readWriteLock.writeLock().unlock();
//        }
//    }
